package com.situ.springboot;

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class TTT {

    public static void main(String[] args) {
        String str1 = "666" + new String("666");
        String str2 = new StringBuilder("abc").toString();
    }

    @Test
    public void test1() {
        // List、Set
        // ArrayList LinkedList
        // Vector ArrayList   HashTable HashMap
        // Map遍历   entrySet   keySet
        HashSet<String> set = new HashSet<>();
        set.add("java");
        set.add("php");
        set.add("ui");
        set.add("java");
        set.add(new String("java"));
        for (String s : set) {
            System.out.println(s);
        }
    }

    @Test
    public void test2() {
        //先比较hashCode，如果hashCode不一样，就一定能放进去，
        // 如果hashCode一样，再比较equals，如果equals不一样，也可以放进去，如果一样，就不能放进去
        HashSet<Student> set = new HashSet<>();
        Student student1 = new Student(1, "zhangsan1", "男");
        Student student2 = new Student(2, "zhangsan2", "男");
        Student student3 = new Student(3, "zhangsan3", "男");
        Student student4 = new Student(3, "zhangsan38", "男");
        set.add(student1);
        set.add(student2);
        set.add(student3);
        set.add(student4);
        for (Student student : set) {
            System.out.println(student);
        }
    }

    @Test
    public void test55() {
        Map<String, String> map = new HashMap<>();
        map.put("cn", "中国");// Entry
        map.put("us", "美国");// Entry
        map.put("uk", "英国");// Entry
        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        for (Map.Entry<String, String> entry : entrySet) {
            System.out.println(entry.getKey() + " : " + entry.getValue());
        }
        System.out.println("---------");
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            System.out.println(key + " ：" + map.get(key));
        }
    }
}
